import Taro from '@tarojs/taro';
import {Command} from '../constant';
import {Dispatch} from 'typings';
import {IAllReducerProps} from '../types';
import {getReducerData} from '@/redux/store';
import api from 'api';
import {extraPathsValue} from '@/redux/util';
import {VAS} from 'wmkit';

export default (dispatch: Dispatch) => {
  let action = {
    commonChange(...param: any) {
      dispatch({
        type: Command.commonChange,
        payload: extraPathsValue(...arguments),
      });
    },

    changeIndex(index) {
      this.commonChange('main.index', index);
    },

    // 分类初始化数据 - 处理操作
    async _initOtherHandle(cateId, cateList, _this = 'content', index?) {
      const token = Taro.getStorageSync('authInfo:token');
      this.changeIndex(index || 0);
      this.commonChange('main.cateList', cateList);

    },
  };
  return action;
};

function getData(): IAllReducerProps {
  return {
    main: getReducerData('packageIGoodsAllListMainGoodsList'),
  };
}

//create by moon https://github.com/creasy2010/moon
